package com.siwei.mes.entity;

import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.fastjson.JSONArray;
import com.siwei.mes.common.validator.AddGroup;
import com.siwei.mes.common.validator.UpdateGroup;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;


/**
 * 设备表(Equipment)实体类
 *
 * @author linzi
 * @since 2023-11-25 22:22:21
 */
@Data
@Accessors(chain = true)
@Table(name = "t_equipment")
@ApiModel(value = "Equipment", description = "设备表")
public class Equipment implements Serializable {
    private static final long serialVersionUID = -44093311667468535L;
    /**
     * 主键id
     */
    @Id
    @ApiModelProperty(value = "设备表主键ID", name = "id")
    private Long id;
    /**
     * 设备编号
     */

    @Column(name = "equipment_no")
    @ApiModelProperty(value = "设备编号", name = "equipmentNo")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "设备编号为空")
    private String equipmentNo;
    /**
     * 设备名称
     */

    @Column(name = "equipment_name")
    @ApiModelProperty(value = "设备名称", name = "equipmentName")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "设备名称为空")
    private String equipmentName;
    /**
     * 设备类型
     */

    @Column(name = "equipment_type")
    @ApiModelProperty(value = "设备类型", name = "equipmentType")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "设备类型为空")
    private String equipmentType;
    /**
     * 出厂编号
     */

    @Column(name = "factory_number")
    @ApiModelProperty(value = "出厂编号", name = "factoryNumber")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "出厂编号为空")
    private String factoryNumber;
    /**
     * 生产厂家
     */

    @Column(name = "manufacturer")
    @ApiModelProperty(value = "生产厂家", name = "manufacturer")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "生产厂家为空")
    private String manufacturer;
    /**
     * 保存地址
     */

    @Column(name = "save_address")
    @ApiModelProperty(value = "保存地址", name = "saveAddress")
    private String saveAddress;
    /**
     * 技术参数
     */

    @Column(name = "technical_parameter")
    @ApiModelProperty(value = "技术参数", name = "technicalParameter")
    private String technicalParameter;
    /**
     * 价格
     */

    @Column(name = "price")
    @ApiModelProperty(value = "价格", name = "price")
    @NotNull(groups = {AddGroup.class, UpdateGroup.class}, message = "价格为空")
    private Double price;
    /**
     * 购置日期
     */

    @Column(name = "buy_time")
    @ApiModelProperty(value = "购置日期", name = "buyTime")
    private Date buyTime;
    /**
     * 启用时间
     */

    @Column(name = "enable_time")
    @ApiModelProperty(value = "启用时间", name = "enableTime")
    private Date enableTime;
    /**
     * 设备状态
     */

    @Column(name = "equipment_status")
    @ApiModelProperty(value = "设备状态", name = "equipmentStatus")
    private String equipmentStatus;
    /**
     * 保管人
     */

    @Column(name = "custody_user_name")
    @ApiModelProperty(value = "保管人", name = "custodyUserName")
    private String custodyUserName;
    /**
     * 试验项目json
     */

    @Column(name = "test_project_json")
    @ApiModelProperty(value = "试验项目json", name = "testProjectJson")
    private JSONArray testProjectJson;
    /**
     * 创建人
     */

    @Column(name = "creater")
    @ApiModelProperty(value = "创建人", name = "creater")
    private Long creater;
    /**
     * 创建时间
     */

    @Column(name = "create_time")
    @ApiModelProperty(value = "创建时间", name = "createTime")
    private Date createTime;
    /**
     * 修改人
     */

    @Column(name = "updater")
    @ApiModelProperty(value = "修改人", name = "updater")
    private Long updater;
    /**
     * 更新时间
     */

    @Column(name = "update_time")
    @ApiModelProperty(value = "更新时间", name = "updateTime")
    private Date updateTime;
    /**
     * 是否删除  1-删除
     */

    @Column(name = "is_del")
    @ApiModelProperty(value = "是否删除  1-删除", name = "isDel")
    private Integer isDel;

    public Equipment init(boolean isCreate) {
        this.setUpdater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                .setUpdateTime(new Date());
        if (isCreate) {
            this.setCreater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                    .setCreateTime(new Date())
                    .setIsDel(0);
        }
        return this;
    }
}
